package com.suzka.mapper;

import com.suzka.pojo.Drug;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 药品数据访问映射接口
 * 使用MyBatis注解方式定义药品相关的数据库操作
 */
@Mapper
public interface DrugMapper {
     @Select("SELECT * FROM drug")
    List<Drug> findAll();
    
    @Select("SELECT * FROM drug WHERE id = #{id}")
    Drug findById(Integer id);
    
    @Insert("INSERT INTO drug(name, type, price, stock, description) VALUES(#{name}, #{type}, #{price}, #{stock}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Drug drug);
    
    @Update("UPDATE drug SET name=#{name}, type=#{type}, price=#{price}, stock=#{stock}, description=#{description} WHERE id=#{id}")
    int update(Drug drug);
    
    @Delete("DELETE FROM drug WHERE id = #{id}")
    int deleteById(Integer id);
    
    @Select("SELECT * FROM drug WHERE name LIKE CONCAT('%', #{keyword}, '%')")
    List<Drug> searchByName(String keyword);

}
